Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
46 lines (38 loc) · 1.13 KB

3.9.2 - Coroutine/PostgreSQL->query.md

File metadata and controls

46 lines (38 loc) · 1.13 KB

Coroutine\PostgreSQL->query

postgresql发送异步非阻塞 协程命令

function Coroutine\PostgreSQL->query(resource $connection);

example:

go(function () {
    $pg = new Swoole\Coroutine\PostgreSQL();
    $conn  = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password=");
    $result = $pg -> query('SELECT * FROM test;');
    $arr = $pg -> fetchAll($result);
    var_dump($arr);
});

返回insert id:

go(function () {
    $pg = new Swoole\Coroutine\PostgreSQL();
    $conn  = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=wuzhenyu password=");
    $result = $pg -> query("insert into test (id,text) VALUES (24,'text') RETURNING id ;");
    $arr = $pg -> fetchRow($result);
    var_dump($arr);
});
?>

也可以多次提交query 命令 ,如begin commit

go(function () {
    $pg = new Swoole\Coroutine\PostgreSQL();
    $conn  = $pg -> connect ("host=127.0.0.1 port=5432 dbname=test user=root password=");
	$pg -> query('BEGIN;');
    $result = $pg -> query('SELECT * FROM test;');
	$arr = $pg -> fetchAll($result);
    $pg -> query('COMMIT;');

    var_dump($arr);
});